﻿using System;
using System.Collections.Generic;

namespace Jayden.Dll.Core.Persistence.Models
{
	public class Namespace
	{
		private Model m_Model;
		private string m_Name;
		private Dictionary<string ,Entity> m_Entities;

		public Namespace(Model model, string name, params Entity[] entities)
		{
			m_Model = model;
			m_Name = name;
			m_Entities = new Dictionary<string, Entity>();
			foreach (Entity e in entities)
				m_Entities.Add(e.Name, e);
		}
		public Namespace(Model model, string name, Configuration config)
		{
			m_Model = model;
			m_Name = name;
			m_Entities = new Dictionary<string, Entity>();
			string[] typeNames = config.GetValues("Entity/@type");
			foreach(string typeName in typeNames)
			{
				Type type = Type.GetType(typeName, true);
				Entity entity = new Entity(this, type);
				m_Entities.Add(entity.Name, entity);
			}
		}

		public bool HaveEntity(string entityName) { return m_Entities != null && m_Entities.ContainsKey(entityName); }
		public Entity this[string entityName] { get { return m_Entities[entityName]; } }
		public string Name { get { return m_Name; } }
		public Model Model { get { return m_Model; } }

		public override string ToString() { return Name; }
	}
}
